//=================================================================
// 
// renderer.h
// 
// Written by Luke Olsen, Jan. 2004
// Based on example code distributed with Qt under GPL license.
//
// Provides a bare-bones implementation of a GL widget under Qt.
// Custom function declarations and class variables can be 
// added here.
// 
//=================================================================

#ifndef RENDERER_H
#define RENDERER_H

#include "Vector3.h"
#include "Point.h"
#include "BSpline.h"
#include "RollerCoaster.h"

#include <math.h>

#include <qgl.h>
#include <qfiledialog.h>
#include <qinputdialog.h>
#include <qdialog.h>
#include <qstring.h>
#include <qtimer.h>
#include <qimage.h>
#include <vector>

const float PI = 3.14159;

class Renderer : public QGLWidget
{
    Q_OBJECT

public:

    Renderer( QWidget* parent, const char* name );
    ~Renderer();
    

    //inline void gmVertex3f(gmVector3 vec){ glVertex3f(vec[0], vec[1], vec[2]); }
    //inline void gmNormal3f(gmVector3 vec){ glNormal3f(vec[0], vec[1], vec[2]); }  
    
signals:

    
public slots:
	void animate();
	
	void xScale(int value);
	void yScale(int value);
	void zScale(int value);
	void uniformScale(int value);
	
	void xView(int value);
	void yView(int value);
	void zView(int value);
	
	void radiusTextChanged(const QString &text);
	void viewTextChanged(const QString &text);
	
	void tangentChanged(bool b);
	void cyclesChanged(int i);
	
	void play();
	void changeView();
	void debug();
	
	//NEW STUFF
	Vector3 screenConvert(float x, float y);
	void display();
	void drawGroundPlane();
	void loadCurve();
	
	void timerDone();

protected:
    // These three functions are REQUIRED for GL widget to operate
    // under Qt. Add custom rendering code to renderer.cpp.
    void initializeGL();
    void paintGL();
    void resizeGL( int w, int h );
    

    // Slots to allow user to interact with GL widget
    void mousePressEvent( QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);
    void mouseDoubleClickEvent(QMouseEvent *e);
    
    void keyPressEvent(QKeyEvent *e);
    
    void createTimer();
    
    

private:
	//methods
	void drawHelix();
	void drawDNA();
	
    // Declare class variables here.
    
    float cameraZ;
    QTimer *timer;

    // Variables for keeping track of mouse events
    int oldx, oldy;
    int button;
    bool mousePressed;
    
    Vector3 scale, uscale;
    float matrix[16];
    
    float radius;
    bool showTangents, bDrawHelix;
    int cycles;
    float xRot, yRot, zRot;
    
    RollerCoaster rollerCoaster;
    int screenWidth, screenHeight;
};

#endif 
